import { getEvents } from '@/api/appliance'
type ErrorInfo = Record<string, string>
type ErrorInfoModel = {
  errorKey: string
  errorDes: string
}
export const NoticeBarErrorInfo: ErrorInfo = {
  'BSH.Common.Event.LowWaterPressure': '供水故障', // 洗衣机、洗干一体机
  'LaundryCare.Common.Event.FatalErrorOccured': '家电出现错误，请描述故障现象',
  'LaundryCare.Common.Event.DoorNotLockable': '门锁失效',
  'LaundryCare.Common.Event.DoorLock.WaterLevelTooHigh': '水位过高',
  'LaundryCare.Washer.Event.PumpError': '排水泵出现问题',
  'LaundryCare.Washer.Event.IDosUnitDefect': 'i-Dos出现问题',
  'Dishcare.Dishwasher.Event.InternalError': '家电出现错误，请描述故障现象',
  'Dishcare.Dishwasher.Event.CheckFilterSystem': '过滤出现问题',
  'Dishcare.Dishwasher.Event.DrainPumpBlocked': '排水泵堵塞',
  'Dishcare.Dishwasher.Event.DrainingNotPossible': '排水失败',
  'Dishcare.Dishwasher.Event.LowVoltage': '电压过低',
  'BSH.Common.Event.AquaStopOccured': '防漏水系统已激活',
  'BSH.Common.Event.LowWaterPressure_DishWasher': '供水水压过低', // 洗碗机,这里其实和第一行的供水故障的key是一样的，为了区别，主动加了个DishWasher
  'Dishcare.Dishwasher.Event.FlexSpray.Error.Blocked': '喷淋臂阻塞',
}
export const NoticeBarProductTypes: string[] = ['Washer', 'WasherDryer', 'Dryer', 'DishWasher', 'Dishwasher']
export async function getApplianceErrorInfo(haId: string, type?: string) {
  const res = await getEvents(haId)
  let events = res.data.events
  let tempArray: string[] = []
  let tempArrayDes: string[] = []

  events.length > 0 &&
    events.forEach((element) => {
      if (Object.keys(NoticeBarErrorInfo).includes(element.key)) {
        let errorDesFlag = type === 'Dishwasher' && element.key === 'BSH.Common.Event.LowWaterPressure'
        tempArray.push(element.key)
        tempArrayDes.push(errorDesFlag ? '供水水压过低' : NoticeBarErrorInfo[element.key])
      }
    })
  return [tempArray, tempArrayDes]
}
